﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace RegexGroupStudy
{
    class Program
    {
        static void Main(string[] args)
        {
            Regex r = new Regex("(i(n))g", RegexOptions.IgnoreCase);

            //1.多个匹配
            MatchCollection mc = r.Matches("Matchingtingstin");
            Console.WriteLine("当前共有{0}个匹配", mc.Count);
            for (int i = 0; i < mc.Count; i++)
            {
                Console.WriteLine("******************");
                Match m = mc[i];
                DisplayMatch(m);
            }

            ////2.一个匹配
            //Match m = r.Match("Matchingtingstin");
            //DisplayMatch(m);
            


            Console.ReadLine();
        }

        private static void DisplayMatch(Match m)
        {
            Console.WriteLine("当前匹配的名称为{0}", m.Value);
            GroupCollection gc = m.Groups;

            Console.WriteLine("共有{0}个组", gc.Count);
            for (int i = 0; i < gc.Count; i++)
            {
                Console.WriteLine("============================");
                Group g = gc[i];
                Console.WriteLine("组{0}在{1}位置", g.Value, g.Index);

                CaptureCollection cc = g.Captures;
                for (int j = 0; j < cc.Count; j++)
                {
                    Console.WriteLine("-------------");
                    Capture c = cc[j];
                    Console.WriteLine("捕获{0}在位置{1}", c.Value, c.Index);
                }
            }
        }
    }
}
